package com.npl.demonplservice;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.*;

/**
 * Created by frankqian on 2018/7/23.
 */
public class Topic {
    public static String gettags(String path) {
        String tag="";
        return tag;
    }

    public static String gettopic(List<String> wordlist) {
        Integer reg_num=0, ave_num=0;

        Map<Double, String> map = new TreeMap<Double, String>(new Comparator<Double>() {
            @Override
            public int compare(Double o1, Double o2) {
                return o1.compareTo(o2);
            }
        });

        try {
            StringBuffer sb = new StringBuffer("");

            FileReader reader = new FileReader("/Users/frankqian/Frank/Study/Lab/sentences.txt");
            BufferedReader br = new BufferedReader(reader);

            String str = null;
            while ((str = br.readLine())!=null) {
                String[] sentence_split = str.split("/");
                double similarity = Similarity.getsimilarity(Segmentation.segInCh(sentence_split[0]), wordlist);
                map.put(similarity, sentence_split[1]);
            }
        } catch (java.io.IOException e) {}

        Integer top = 0;
        Iterator<Double> iter = map.keySet().iterator();
        while (iter.hasNext()&&top<10) {
            Double key = iter.next();
            if (map.get(key)=="reg") reg_num++;
            else if (map.get(key)=="ave") ave_num++;
            top++;
        }
        return (reg_num>ave_num)?"regression":"average";
    }
}
